<include file="Common/header" />
<title>房间录入</title>
<script type="text/javascript" src="__PUBLIC__/h-ui/lib/jquery/1.9.1/jquery.form.js"></script>
</head>
<body>
<div class="pd-20">
	<div class="panel panel-primary">
		<div class="panel-header">基本信息</div> 
		<table class="table table-border table-bordered table-striped">
            <tr>
               	<td style="background-color: #f9f9f9;text-align: right">门锁串号：</td>
                <td style="background-color: white">
					<input type="hidden" name="lock_id" id="lock_id" value="{$lockinfo['lock_id']}" />
					<input type="text" name="lock_sn" id="lock_sn" class="input-text radius" value="{$lockinfo['lock_sn']}" />
				</td>
				<td style="background-color: #f9f9f9;text-align: right">中控网关：</td>
                <td style="background-color: white">
					<input type="text" name="lock_boxsn" id="lock_boxsn" class="input-text radius" value="{$lockinfo['lock_boxsn']}" />
				</td>
				<td style="background-color: #f9f9f9;text-align: right">门锁类型：</td>
                <td style="background-color: white">
					<span class="select-box radius">
						<select class="select" size="1" name="locktype" id="locktype">
							<option value="0">--请选择门锁类型--</option>
							<?php if(count($locktype)) foreach($locktype as $sp){ ?>
							<option value="{$sp['ptype']}" {$lockinfo['lock_type'] == $sp['ptype'] ? 'selected' : ''}>{$sp['title']}</option>
							<?php } ?>
						</select>
					</span>
				</td>
            </tr>
            <tr>
               	<td style="background-color: #f9f9f9;text-align: right">所属分店：</td>
                <td style="background-color: white">
					<span class="select-box radius">
						<select class="select" size="1" name="shop_id" id="shop_id">
							<option value="0">--请选择分店--</option>
							<?php foreach($shoplist as $spl){ ?>
							<option value="{$spl['shop_id']}" {$lockinfo['shop_id'] == $spl['shop_id'] ? 'selected' : ''}>{$spl['title']}</option>
							<?php } ?>
						</select>
					</span>
				</td>
				<td style="background-color: #f9f9f9;text-align: right">所属小区：</td>
                <td style="background-color: white;">
					<span class="select-box radius">
						<select class="select" size="1" name="villageid" id="villageid">
							<option value="0">--请选择小区--</option>
							<?php foreach($villagelist as $vls){ ?>
							<option value="{$vls['villageid']}" {$lockinfo['villageid'] == $vls['villageid'] ? 'selected' : ''}>{$vls['title']}</option>
							<?php } ?>
						</select>
					</span>
                </td>
				<td style="background-color: #f9f9f9;text-align: right">房间号：</td>
                <td style="background-color: white;">
					<input type="text" name="doornumber" id="doornumber" class="input-text radius" value="{$lockinfo['doornumber']}" />
                </td>
            </tr>
		</table>
	</div>
	<div style="padding-top: 10px;">
		<table>
			<tr class="text-c">
				<td colspan="6">
					<button type="button" class="btn btn-success radius submitBtn" id="admin-role-save" name="admin-role-save">
						<i class="icon-ok"></i> 确  定
					</button>
				</td>
			</tr>
		</table>
	</div>
</div>
<script>
	var imagelist = <?php echo json_encode($roominfo['images']);?>;
	function uploadImages(formName){
		var load = layer.load(2);
		$("#"+ formName).ajaxSubmit({
			type:'post',
			url:'../index/upload.html',
			success:function(data){
				layer.close(load);
				var data = JSON.parse(data);
				if(data.errCode/1 > 0){
					layer.msg('上传成功', {icon:1, time: 2000});
					if(formName == 'uploadform'){
						$("#images").val(data.errMsg);
						$("#imgshow").show();
						$("#imgshow img").attr('src', "__PUBLIC__/upload/"+ data.errMsg);
					}else{
						imagelist.push(data.errMsg); //保存图片
						data.errMsg = "__PUBLIC__/upload/" + data.errMsg;
						var img = '<img src="'+ data.errMsg +'" style="width: 100px; height: 100px; margin-right:10px;" class="radius" />';
						$("#imgshow2").show();
						$("#imgshow2 div").append(img);
					}
				}else{
					layer.msg(data.errMsg, {icon:2, time: 2000});
				}
			},
			error:function(XmlHttpRequest,textStatus,errorThrown){
				
			}
		});
	}
	
	function isNumber(s){
	    var regu = "^[0-9]+\.?[0-9]*$";
	    var re = new RegExp(regu);
	    if(re.test(s)){
	        return true;
	    }else{
	        return false;
	    }
	}

	$(document).ready(function(){
		//房间来源
		$("#lease_type").on('change', function(){
			if($(this).val()/1 == 2){
				$("div.landlord").show();
			}else{
				$("div.landlord").hide();
			}
		});

		//根据分店ID获取小区列表
		$("#shop_id").on('change', function(){
			var shopid = $(this).val();
			$.get('../shop/getvillage.html', {shopid: shopid}, function(data){
				$("#villageid").html(data);
			});
		});

		/**
		 * 提交数据
		 **/
		$(".submitBtn").on('click', function(){
			var data = {};
			var locksn = $("#lock_sn").val() || "";
			if(locksn.length <= 0){
				layer.msg("请输入门锁串号", {icon: 2, time:2000});
				return false;
			}else{
				data.lock_sn = locksn;
			}

			data.lock_type = $("#locktype").val();
			if(data.lock_type/1 == 0){
				layer.msg('请选择门锁类型', {icon: 5, time: 2000});
				return false;
			}

			//房间ID
			data.lockid = $("#lock_id").val();
			data.shop_id = $("#shop_id").val();
			if(data.shop_id/1 == 0){
				layer.msg('请选择分店', {icon: 5, time: 2000});
				return false;
			}

			data.villageid = $("#villageid").val();
			if(data.villageid/1 == 0){
				layer.msg('请选择小区', {icon: 5, time: 2000});
				return false;
			}
/*
			if($("#doornumber").val() == ""){
				layer.msg("请输入房间编号", {icon: 2, time:2000});
				return false;
			}else{
				data.doornumber = $("#doornumber").val();
			}
*/			data.doornumber = $("#doornumber").val();
			var lock_boxsn = $("#lock_boxsn").val() || "";
			data.lock_boxsn = lock_boxsn;

			var load = layer.load(2);
			$.post('lockadd.html', data, function(row){
				layer.close(load);
				if(row/1 == 1){
					layer.msg('编辑成功', {icon: 1, time: 2000}, function(){
						window.parent.location.reload(); //刷新
						var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    	parent.layer.close(index);
					});
				}else if(row/1 == 2){
					layer.msg('房间号输入错误', {icon: 5, time: 2000});
				}else{
					layer.msg('编辑失败', {icon: 0, time: 2000});
				}
			});
		});
	});
</script>
</body>
</html>